import type { DescData } from '@arco-design/web-vue/es/descriptions/interface'
import axios from 'axios'
import qs from 'query-string'

export interface PageQuery{
    current: number
    pageSize: number
    name?: string
}

export interface GoodRecord {
    id: number,
    name: string | null
    sort: number
    visibility: boolean
}

export interface GoodPageRes{
    list: GoodRecord[],
    total: number
}

export interface GoodDetail extends GoodRecord {
    id: number,
    name: string | null
    sort: number
    visibility: boolean
}

// 分页查询会员
export function queryGoodPage(params: PageQuery) {
    return axios.get<GoodPageRes>('/api/good/page',{
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj)
        },
    })
}

// 获取会员详情
export function getGoodDetail(id: number) {
    return axios.get<GoodDetail>(`/api/good/${id}`)
}

// 编辑会员信息
export function updateGood(data: GoodDetail) {
    return axios.put('/api/good', data)
}

// 启用/禁用会员
export function toggleGoodStatus(id: number) {
    return axios.put(`/api/good/enable/${id}`)
}

// 删除会员
export function deleteGood(ids: number[]) {
    return axios.delete('/api/good', {
        data: ids
    })
}